package com.example.cinema.adapter;

import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.cinema.R;

import java.util.List;

public class CircleAdapter<T> extends BaseAdapter {

    private List<T> list;
    private LayoutInflater inflater;
    private Context context;
    public CircleAdapter(List<T> list, Context context) {
        this.list = list;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    private FuYong fuYong;
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null)
        {
            convertView =  inflater.inflate(R.layout.circle_image_item,null);
            fuYong = new FuYong();

            fuYong.closeview = convertView.findViewById(R.id.close);
            fuYong.imageView = convertView.findViewById(R.id.image);
            convertView.setTag(fuYong);
        }else {
            fuYong =(FuYong)convertView.getTag();
        }
        Log.i("UUU",list.get(position).toString());
        Log.i("UUU",list.size()+"数量");
        if(position>0)
        {
           fuYong.imageView.setImageURI((Uri) list.get(position));
        }else {
            fuYong.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            fuYong.imageView.setImageDrawable(context.getDrawable(R.mipmap.upimages));
        }
        if(position>0)
        {
            fuYong.closeview.setImageDrawable(context.getDrawable(R.mipmap.imgclose));
        }
        if(listener != null)
        {
            fuYong.closeview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.Close(position);
                }
            });

        }
        return convertView;
    }

    class FuYong{
        public ImageView imageView;
        public ImageView closeview;
    }


    public interface  setOnImageClose{
        void Close(int positon);
    }
    private setOnImageClose listener;
    public void setOnImageCloseListener(setOnImageClose closeListener){
        listener=closeListener;
    }
}
